package com.turing.job.admin.job;

import java.time.LocalDate;

import org.springframework.stereotype.Component;

import com.turing.common.util.Log;
import com.turing.job.admin.dao.XxlJobLogDao;
import com.turing.job.admin.model.dto.XxlLogDto;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;

/**
 * @Description 删除日志任务
 * @Author lcy
 * @Date 2021/5/31 15:19
 */
@Component
@AllArgsConstructor
public class DeleteLogJob {

    /**
     * 任务日志表
     */
    private final XxlJobLogDao xxlJobLogDao;

    @XxlJob("deleteLogJob")
    public void deleteLogJob() {

        Log.info("deleteLogJob start ");
        LocalDate now = LocalDate.now();
        //LocalDate dayAgo = now.minusDays(1);
        XxlLogDto xxlLogDto = XxlLogDto.builder().beforeDate(now).build();
        int count = xxlJobLogDao.deleteOldLog(xxlLogDto);
        Log.info("deleteLogJob end,delete count = {}", count);

    }

}
